const mongoose = require("mongoose");
const BookModel = require('./BookModel')

const authorSchema = new mongoose.Schema({
  name: String,
  age: Number,
});
authorSchema.pre("remove", function (next) {
  // 在删除作者之前删除关联的书籍
  console.log({ author: this._id });
  BookModel.deleteMany({ author: this._id });
  next();
});
const authorModel = mongoose.model("Author", authorSchema);

module.exports = authorModel;
